# 程序运行文件

import tornado.web
import tornado.ioloop
from multiprocessing import Process
from handlers import handlers
from config import config

settings = {

}


class Application(tornado.web.Application):
    def __init__(self):
        super(Application, self).__init__(handlers=handlers, **settings)


def run(port):
    print("server is running by %s" % str(port))
    app = Application()
    app.listen(port, xheaders=True)
    tornado.ioloop.IOLoop().current().start()


def main():
    if config["pro_type"] == 1:
        for port in range(config["port_start"], config["port_end"] + 1):
            p = Process(target=run, args=(port,))
            p.start()
    else:
        run(config["port_start"])


if __name__ == '__main__':
    main()
